#基类Base
#显示等待
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#Keys事件
from selenium.webdriver.common.keys import Keys
class Base():
    #初始化方法
    def __init__(self,driver):
        self.driver = driver
    #浏览器方法
    def open_url(self,url):
        self.driver.get(url)
    #定位元素方法
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(
                lambda driver: self.driver.find_element(*loc).is_displayed
            )
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
    #点击事件方法
    def click(self,loc):
        self.find_element(loc).click()
    #键盘输入方法
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    #文本方法
    def text(self,loc):
        return self.find_element(loc).text
    #清空方法
    def clear(self,loc):
        self.find_element(loc).clear()
    #回车方法
    def Enter(self,loc):
        self.find_element(loc).send_keys(Keys.ENTER)

    #滚动事件方法
    def scroll_to_x(self,x):
        self.driver.execute_script(f'window.scrollTo(0,{x})')
    #切换窗口方法
    def new_window(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])

    #截图方法
    def screenshot(self,jiuxian):
        self.driver.save_screenshot(f'{jiuxian}.png')


